{
    let BTN_MAP = {
        "match" : "res/match/btn_match.png",
        "ready" : "res/match/btn_ready.png",
        "cancel" : "res/match/btn_cancel.png"
    };

    class Members extends ui.Match.MembersUI {
        constructor () {
            super();

            this.mapId = null;
            
            this.init();
        }

        destroy () {
            super.destroy();
            Sail.io.unregister("ready", this.onStatusChange);
        }

        init () {
            this.left = 125;
            this.bottom = 113;

            this.initEvent();
        }

        initEvent () {
            this.btnStart.on(Laya.Event.CLICK, this, this.onMatchClick);

            Sail.io.register("ready", this, this.onStatusChange);
        }

        onMatchClick () {
            switch (this.btnStart.skin) {
                case BTN_MAP["match"]:
                    Sail.io.emit("match", {mapId : this.mapId});
                    break;
                case BTN_MAP["ready"]:
                    Sail.io.emit("ready", {status : 1});
                    break;
                case BTN_MAP["cancel"]:
                    Sail.io.emit("ready", {status : 0});
                    break;
            }
        }

        onStatusChange (data, code, msg) {
            if(code != 0){
                Sail.director.popScene(new Alert.Tips(msg));
                return;
            }
            let status = this[`player${data.pos}`].getChildByName("content").getChildByName("status");

            switch (`${data.status}`) {
                case "1":
                    (data.uid == GM.user_id) && (this.btnStart.skin = BTN_MAP["cancel"]);
                    status.text = "准备完毕";
                    status.color = "#79ff4a";
                    break;
                case "0":
                    (data.uid == GM.user_id) && (this.btnStart.skin = BTN_MAP["ready"]);
                    status.text = "准备中";
                    status.color = "#ffe063";
                    break;
            }
        }

        updateAll (data, mapId) {
            this.mapId = mapId;
            let playerData = data.player;
            if(data.cap.uid == GM.user_id){
                this.btnStart.skin = BTN_MAP["match"];
            }else{
                this.btnStart.skin = BTN_MAP["ready"];
            }
            this.updateView(this.captain, data.cap);
            
            if(!playerData){return;}
            for(let i = 0; i < playerData.length; i++){
                // let _data = playerData[i];
                // let player = this[`player${_data.pos}`];
                // let playerEle = player.getChildByName("content");
                
                // this.updateView(playerEle, _data);
                // playerEle.visible = true;
                // player.getChildByName("empty").visible = false;
                this.update(playerData[i]);
            }
        }

        update (data) {
            let player = this[`player${data.pos}`];
            let playerEle = player.getChildByName("content");
            
            this.updateView(playerEle, data);
            playerEle.visible = true;
            player.getChildByName("empty").visible = false;
        }

        kickUser (pos) {
            let player = this[`player${pos}`];

            player.getChildByName("content").visible = false;
            player.getChildByName("empty").visible = true;
        }

        updateView (ele, data) {
            ele.getChildByName("userName").text = data.ue;
            ele.getChildByName("avatar").skin = `res/role_icon/icon_${data.icon}.png`;
            if(data.st == 0){
                ele.getChildByName("status").text = "准备中";
                ele.getChildByName("status").color = "#ffe063";
            }else{
                ele.getChildByName("status").text = "准备完毕";
                ele.getChildByName("status").color = "#79ff4a";
            }
            ele.getChildByName("medal").text = data.gd;
            ele.getChildByName("cup").text = data.hm;
            ele.getChildByName("level").text = data.hl;
        }

        resize (width, height, rate) {
            this.scale(rate, rate);
        }
    }

    Sail.class(Members, "Com.Match.Members");
}